//
//  MyFriendControl.m
//  FreeTime
//
//  Created by  on 16/8/31.
//  Copyright © 2016年 SRDZ.com. All rights reserved.
//

#import "MyFriendControl.h"
#import "Header.h"
#import "MyFriendCell.h"
#import "MyFriendTextCell.h"
#import "PhotoBrowserControl.h"
@interface MyFriendControl (){
    UIImageView * tableHeaderImg;
    NSInteger index;
    UILabel * nameLbl,*textViewPlace;
    UIButton * messageBtn,* iconBtn;
    NSIndexPath * indexePathCell;
    NSMutableArray * dataArr;
    
}


@end

@implementation MyFriendControl

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNav];
    [self loadOrignData];
    [self setupUI];
}
#pragma mark -- selfStyle --
- (void)setupUI{
    self.navigationItem.title = @"德玛西亚";
    self.tableView.frame = CGRectMake(0, -64, WindowWidth, WindowHeight);
    self.tableView.backgroundColor = RGB_COLOR(244, 243, 237);
    tableHeaderImg = [ReduceCode creatImageVeiwWithFrame:CGRectMake(0, 0, WindowWidth, 280) imageName:@"123" isCorner:NO];
    tableHeaderImg.image = [[UIImage imageNamed:@"123"] applyDarkEffect];
    iconBtn = [ReduceCode creatBtnWithFrame:CGRectMake(10, 180, 60, 60) btnTitle:@"" btnTitleColor:nil btnTitleFont:20 btnBackgroundColor:nil backgroundImage:[UIImage imageNamed:@"123"] isCorner:YES];
    nameLbl = [ReduceCode creatLabelWithFrame:CGRectMake(CGRectGetMaxX(iconBtn.frame)+10, CGRectGetMidY(iconBtn.frame)-7.5, 160, 15) title:@"可爱的西红柿" titleColor:[UIColor whiteColor] font:15 textAlignment:0];
    [tableHeaderImg addSubview:nameLbl];
    [tableHeaderImg addSubview:iconBtn];
    self.tableView.tableHeaderView = tableHeaderImg;
}
- (void)loadOrignData{
    dataArr = [NSMutableArray arrayWithArray:@[@[@{@"image":@"1",@"title":@"堵车了那么的厉害那么的残忍,这个时间才慢慢的到了家,夜已深,万籁寂静,说不定啊明天更堵啦"}],@[@{@"image":@"1",@"title":@"这个杀手不太冷"},@{@"image":@"0",@"title":@"我这个是第二"}],@[@{@"image":@"0",@"title":@"我是个牛仔,你知道吗 爱你并不容易还需要更多勇气 是天意吧,让我爱上你"}]]];
    NSLog(@"%@",dataArr);
//    NSArray * commentArr = @[@"8月31",@"8月30",@"8月29"];
    
    
    
//    for (int i = 0; i<3; i++) {
//        
////        NSArray * arr = @[@{@"image":}]
//        [self.dataArray addObject:dict];
//    }
    NSLog(@"======%@",dataArr);
}

#pragma mark tableViewMethord
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [dataArr[section] count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return dataArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    NSMutableArray * arr = [NSMutableArray arrayWithArray:dataArr[indexPath.section]];
    NSDictionary * dict;
    if ([dataArr[indexPath.section][indexPath.row][@"image"] intValue] == 0) {
        dict = [MyFriendTextCell cellFrame:dataArr[indexPath.section][indexPath.row] indexPath:indexPath];
    }else{
        dict = [MyFriendCell cellFrame:dataArr[indexPath.section][indexPath.row] indexPath:indexPath];
    }
    [arr replaceObjectAtIndex:indexPath.row withObject:dict];
    dataArr[indexPath.section] = arr;
    return [dict[@"cellHeight"] integerValue];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, 30)];
    whiteView.backgroundColor = RGB_COLOR(244, 243, 237);
    return whiteView;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([dataArr[indexPath.section][indexPath.row][@"image"] intValue] == 0) {
        static NSString * cellIdentifier = @"MyFriendTextCell";
        MyFriendTextCell * cell = [tableView cellForRowAtIndexPath:indexPath];
        if (cell == nil) {
            cell = [[MyFriendTextCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
        }
        if (indexPath.row != 0) {
            cell.dayLbl.hidden = YES;
            cell.monthLbl.hidden = YES;
        }
        cell.backgroundColor = RGB_COLOR(244, 243, 237);
        [cell bindData:dataArr[indexPath.section][indexPath.row] indexPath:indexPath];
        return cell;
    }
    static NSString * cellIdentifier = @"MyFriendCell";
    MyFriendCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    if (cell == nil) {
        cell = [[MyFriendCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    if (indexPath.row != 0) {
        cell.dayLbl.hidden = YES;
        cell.monthLbl.hidden = YES;
    }
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapPhoto)];
    [cell.imgView addGestureRecognizer:tap];
    
    cell.backgroundColor = RGB_COLOR(244, 243, 237);
    cell.tag = 100+indexPath.row;
    [cell bindData:dataArr[indexPath.section][indexPath.row] indexPath:indexPath];
    return cell;
}
#pragma mark -- 手势响应 -- 
- (void)tapPhoto{
    [self.navigationController pushViewController:[PhotoBrowserControl new] animated:YES];
}
@end
